﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using Negocio;
using System.Collections.ObjectModel;

namespace Persistencia
{
    //crear la interfaz en el dominio :IPersistencia y usarla en esta clase

    public class FPersistence:IPersistence
    {
        private ConnectionDB conn;

        //Constructor

        public FPersistence() 
        {
            this.conn = ConnectionDB.getInstance("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Parameters.dataSource);        
        }

        public ConnectionDB Conn
        {
            get { return conn; }
            set { conn = value; }
        }
        public void add(object o) 
        {
            Broker br = Broker.createBroker(o);
            br.add(o);
        }
        public void update(object o)
        {
            Broker br = Broker.createBroker(o);
            br.update(o);
        }
        public void delete(object o)
        {
            Broker br = Broker.createBroker(o);
            br.delete(o);
        }
        public void bringData(object o)
        {
            Broker br = Broker.createBroker(o);
            br.bringData(o);
        }
        public ObservableCollection<Object> bringList(object o)
        {
            Broker br = Broker.createBroker(o);
            return br.bringList(o);
        }
        public void connect(string cadena) 
        {
            conn.connect();
        }
        public void disconnect()
        {
            conn.disconnect();
        }
        public int bringLastOID()
        {
            return this.Conn.bringOID();
        }
        public ObservableCollection<string> loadEvaluationWithGroup(DateTime date) {

            conn.connect();
            ObservableCollection<string> list = new ObservableCollection<string>();
            string sql = "Select distinct EvaluationName,groupName from PlayerExecution where date_ like('" + date.ToShortDateString() + "')";
            this.conn.bringList(sql);
            while (this.conn.nextRecord())
            {
                string caracter="";
                caracter = this.conn.getDataString("EvaluationName").ToString() + ", " + this.conn.getDataString("groupName").ToString();
                list.Add(caracter);

            }
            return list;
        }
    
    }
}
